<?php
/**
 * Created by PhpStorm.
 * User: 低调
 * Date: 2018/5/19
 * Time: 21:44
 */
//普通用户修改密码，直接修改，修改后正常使用
include("../connectdb.php");
session_start();
if(isset($_POST['submit'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];
    if ($password == $_POST['password2']) {
        $sql = "SELECT username FROM normalUser WHERE email='" . $email . "'";
        $result = mysqli_fetch_array(mysqli_query($conn, $sql));
        if ($result) {
            if ($result['username'] == $_POST['username']) {
                $sql = "UPDATE normalUser SET password='".$password."' WHERE email='".$email."'";
                mysqli_query($conn,$sql);
                echo "<script>alert('修改成功');location.href='login.php';</script>";
            }
            else
                echo "<script>alert('邮箱与用户名不匹配');history.go(-1);</script>";
        } else {
            echo "<script language=\"JavaScript\">alert('该邮箱未注册');history.go(-1)</script>";
        }
    }
    else
        echo "<script>alert('两次输入的密码不一致');history.go(-1);</script>";
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Blogs 密码修改</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="../admin/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="../admin/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="../admin/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="../admin/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="../admin/assets/css/app.css">
    <script src="../admin/assets/js/jquery.min.js"></script>

</head>

<body data-type="login">
<script src="../admin/assets/js/theme.js"></script>
<script language=JavaScript>
    function Checkpost(){
        if (form1.email.value==""){
            alert("邮箱不能为空");
            form1.email.focus();
            return false;
        }
        if(form1.username.value==""){
            alert("用户名不能为空");
            form1.username.focus();
            return false;
        }
        if(form1.password.value==""){
            alert("密码不能为空");
            form1.password.focus();
            return false;
        }
    }
</script>
<div class="am-g tpl-g">
    <!-- 风格切换 -->
    <div class="tpl-skiner">
        <div class="tpl-skiner-toggle am-icon-cog">
        </div>
        <div class="tpl-skiner-content">
            <div class="tpl-skiner-content-title">
                选择主题
            </div>
            <div class="tpl-skiner-content-bar">
                <span class="skiner-color skiner-white" data-color="theme-white"></span>
                <span class="skiner-color skiner-black" data-color="theme-black"></span>
            </div>
        </div>
    </div>
    <div class="tpl-login">
        <div class="tpl-login-content">
            <div class="tpl-login-title">重设密码</div>
            <span class="tpl-login-content-info">
                  用户重设密码
              </span>


            <form class="am-form tpl-form-line-form" method="post" action="" name="form1" onsubmit="return Checkpost()">
                <div class="am-form-group">
                    <input type="text" class="tpl-form-input" id="user-name" placeholder="邮箱" name="email">

                </div>

                <div class="am-form-group">
                    <input type="text" class="tpl-form-input" id="user-name" placeholder="用户名" name="username">
                </div>

                <div class="am-form-group">
                    <input type="password" class="tpl-form-input" id="user-name" placeholder="输入新密码" name="password">
                </div>

                <div class="am-form-group">
                    <input type="password" class="tpl-form-input" id="user-name" placeholder="再次输入密码" name="password2">
                </div>

                <div class="am-form-group">
                    <input type="submit" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn" name="submit" value="确认修改">

                </div>
            </form>
        </div>
    </div>
</div>
<script src="../admin/assets/js/amazeui.min.js"></script>
<script src="../admin/assets/js/app.js"></script>

</body>

</html>